//
//  AddPayPage.swift
//  Uber
//
//  Created by 朱 桓 on 16/1/11.
//  Copyright © 2016年 zhu.huan. All rights reserved.
//

import UIKit

class AddPayPage: ZhBasePage,UITableViewDataSource,UITableViewDelegate {

    @IBOutlet weak var tableView: UITableView!
    
    var datas:[PayInfo]!
    
    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        self.title = "添加付款方式"
        
        setNavigationItem("Back.png", selector: "doBack", isRight: false)
        setNavigationItem("验证", selector: "doVerifyPhone", isRight: true)
        
        // 初始化table数据
        initDatas();
        
        // 创建一个重用的单元格
        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "CellID")
        self.view.addSubview(self.tableView)
        
        self.tableView.reloadData()
    }
    
    /**
    *跳转到验证窗口
    */
    func doVerifyPhone()
    {
        let page = VerifyPhonePage()
        
        self.navigationController?.pushViewController(page, animated: true)
    }
    
    func initDatas()
    {
        var data:PayInfo!
        let dict:[String:String] = ["百度钱包":"BaiDuWallet.png",
            "银联":"YinLian.png", "支付宝":"AliPay.png", "国际信用卡":"CreditCard.png"]
        datas = []
        for (key,value) in dict {
            data = PayInfo()
            data.name = key
            data.icon = value
            
            datas.append(data)
        }
    }

    /**
    *设置行数
    */
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return datas.count
    }

    /**
    *设置单元格
    */
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let identify:String = "CellID"
        let cell = tableView.dequeueReusableCellWithIdentifier(identify, forIndexPath: indexPath) as UITableViewCell
        
        let data = datas[indexPath.row]
    
        cell.textLabel?.text = data.name
        cell.imageView?.image = UIImage(named: data.icon)
        
        return cell
    }

    /**
    *选中单元格
    */
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
    {
        // 取消自动点击痕迹
        self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
        
        // 判断点击的是哪种付款方式
        let page = YinLianPage()
        
        self.navigationController?.pushViewController(page, animated: true)
    }
    

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
    }

}
